// Saves options to localStorage.
function save_options() {
	var select = document.getElementById("linksIntervalTime");
	var _value = select.children[select.selectedIndex].value;
	localStorage["links_interval_time"] = _value;

	select = document.getElementById("linksLimit");
	_value = select.children[select.selectedIndex].value;
	localStorage["links_limit"] = _value;

	// Update status to let user know options were saved.
	gu.updateStatus("status", "Options Saved.");
}

// Restores select box state to saved value from localStorage.
function restore_options() {
	var _value = gu.getOption("links_interval_time", gu.defaultIntervalTime);
	var _select = document.getElementById("linksIntervalTime");
	for ( var i = 0; i < _select.children.length; i++) {
		var child = _select.children[i];
		if (child.value == _value) {
			child.selected = true;
		} else {
			child.selected = false;
		}
	}

	_value = gu.getOption("links_limit", gu.defaultLinksLimit);
	_select = document.getElementById("linksLimit");
	for ( var i = 0; i < _select.children.length; i++) {
		var child = _select.children[i];
		if (child.value == _value) {
			child.selected = true;
		} else {
			child.selected = false;
		}
	}
}

document.addEventListener('DOMContentLoaded', restore_options);
gu.$('#save').addEventListener('click', save_options);